package com.woniu.fly.fairmall.admin.web;

import com.woniu.fly.fairmall.admin.annotation.RequiresPermissionsDesc;
import com.woniu.fly.fairmall.core.util.ResponseUtil;
import com.woniu.fly.fairmall.db.entity.FairmallUser;
import com.woniu.fly.fairmall.db.service.FairmallUserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Validated
public class AdminUserController {
    private final Log logger = LogFactory.getLog(AdminUserController.class);

    @Resource
    private FairmallUserService userService;

    @RequiresPermissions("admin:user:list")
    @RequiresPermissionsDesc(menu = {"用户管理", "会员管理"}, button = "查询")
    @GetMapping("/list")
    public Object list(String username, String mobile,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {
        List<FairmallUser> fairmallUsers = userService.queryAllListByPage(username, mobile, page, limit);
        return ResponseUtil.okList(fairmallUsers);
    }

}
